<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>

<script>

    function check0(){
        $.ajax({
            type:"post",
            url:"mock.json",
            async: false,
            contentType: "application/json;charset=UTF-8",//请求的媒体类型
            dataType:"json",//返回对象
            success: (res)=>{
                console.log(res)
                return -1
            },
            error: function(e) {
                console.log("失败"+e);
            }
        });
    }

    function check(){
        let aa
        $.ajax({
            type:"post",
            url:"mock.json",
            async: false,
            contentType: "application/json;charset=UTF-8",//请求的媒体类型
            dataType:"json",//返回对象
            success: (res)=>{
                console.log(res)
                aa = -1
            },
            error: function(e) {
                console.log("失败"+e);
            }
        });
        return aa
    }

    function check2(){
        return new Promise((resolve, reject) => {
            $.ajax({
                type:"post",
                url:"mock.json",
                contentType: "application/json;charset=UTF-8",//请求的媒体类型
                dataType:"json",//返回对象
                success: (res)=>{
                    console.log(res)
                    resolve(-1)// resolve表示成功 用.then接收
                },
                error: (e)=> {
                    reject(e)//reject表示失败 用.catch接收
                }
            });
        })
    }

    check2().then((res)=>{
        console.log("res:",res)
    }).catch((err) => {
        console.log("err:",err)
    })
</script>

</body>
</html>
